var city = "沧州";

function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var json = JSON.parse(xmlhttp.responseText);
            console.log(json);
            console.log(json.daily_forecast[1].date);
            for (let i = 0;i < json.daily_forecast.length; i++){
                var cit = document.querySelectorAll(".city");
                cit[i].innerHTML = json.daily_forecast[i].date;
                var now = document.querySelectorAll(".now");
                now[i].innerHTML = json.daily_forecast[i].cond.txt_d;
                var drs = document.querySelectorAll(".drsg");
                drs[i].innerHTML = json.daily_forecast[i].tmp.max + "℃";
                var small = document.querySelectorAll(".small");
                small[i].innerHTML = "/" + json.daily_forecast[i].tmp.min + "℃";
                var wind = document.querySelectorAll(".wind");
                wind[i].innerHTML = json.daily_forecast[i].wind.dir;
                var sc = document.querySelectorAll(".sc");
                if (json.daily_forecast[i].wind.sc == "1-2"){
                    json.daily_forecast[i].wind.sc = "<3级";
                    sc[i].innerHTML = json.daily_forecast[i].wind.sc;
                }else {
                    sc[i].innerHTML = json.daily_forecast[i].wind.sc + "级";
                }
                var span_one = document.querySelector("#span-one");
                span_one.innerHTML = json.suggestion.uv.brf;
                var p_one = document.querySelector("#p-one");
                p_one.innerHTML = json.suggestion.uv.txt;
                var p_two = document.querySelector("#p-two");
                p_two.innerHTML = json.suggestion.trav.txt;
                var span_three = document.querySelector("#span-three");
                span_three.innerHTML = json.suggestion.flu.brf;
                var p_three = document.querySelector("#p-three");
                p_three.innerHTML = json.suggestion.flu.txt;
                var span_fore = document.querySelector("#span-fore");
                span_fore.innerHTML = json.suggestion.drsg.brf;
                var p_fore = document.querySelector("#p-fore");
                p_fore.innerHTML = json.suggestion.drsg.txt;
                var span_five = document.querySelector("#span-five");
                span_five.innerHTML = json.suggestion.cw.brf;
                var p_five = document.querySelector("#p-five");
                p_five.innerHTML = json.suggestion.cw.txt;
                var span_six = document.querySelector("#span-six");
                span_six.innerHTML = json.suggestion.air.brf;
                var p_six = document.querySelector("#p-six");
                p_six.innerHTML = json.suggestion.air.txt;
                //document.querySelector("#brf").innerHTML = json.suggestion.uv.brf;
                //document.querySelector("#txt").innerHTML = json.suggestion.uv.txt;
                var tim = document.querySelectorAll(".time");
                tim[i].innerHTML = json.hourly_forecast[i].date.slice(10);
                var tmp = document.querySelectorAll(".tmp");
                tmp[i].innerHTML = json.hourly_forecast[i].tmp + "℃";
                var stip = document.querySelectorAll(".stip");
                stip[i].innerHTML = json.hourly_forecast[i].wind.dir;
                var claa = document.querySelectorAll(".class");
                if (json.hourly_forecast[i].wind.sc == "1-2"){
                    json.hourly_forecast[i].wind.sc = "<3级";
                    claa[i].innerHTML = json.hourly_forecast[i].wind.sc;
                }else {
                    claa[i].innerHTML = json.hourly_forecast[i].wind.sc + "级";
                }
            }

            //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city=" + city,true);
    xmlhttp.send();
}
loadXMLDoc();

document.querySelector("#ipt").addEventListener('change',function(){
    console.log(this.value);
    city = this.value;
    loadXMLDoc();
});

var btn1 = document.querySelector(".btn1");
var btn2 = document.querySelector(".btn2");
var bm = document.querySelector(".bottom-end");
var nex = document.querySelector(".nex");
btn2.addEventListener('click',function(){
    bm.style.display = "block";
    nex.style.display = "none";
    btn2.className = "ss";
    btn1.className = "btn1";
});
btn1.addEventListener('click',function(){
    nex.style.display = "block";
    bm.style.display = "none";
    btn1.className = "ss";
    btn2.className = "btn1";
});